/**
 * 书签路由
 * 处理书签的创建、读取、更新、删除和导入操作的路由
 */

const express = require('express');
const {
  getBookmarks,
  getBookmark,
  createBookmark,
  updateBookmark,
  deleteBookmark,
  incrementClickCount,
  getTags,
  createBookmarksBatch,
  importBookmarksFromHtml
} = require('../controllers/bookmarks');
const { protect, authorize } = require('../middleware/auth');

const router = express.Router();

// 公开路由
router.get('/', getBookmarks);
router.get('/tags', getTags);
router.get('/:id', getBookmark);
router.put('/:id/click', incrementClickCount);

// 需要身份验证和管理员权限的路由
router.post('/', protect, authorize('admin'), createBookmark);
router.put('/:id', protect, authorize('admin'), updateBookmark);
router.delete('/:id', protect, authorize('admin'), deleteBookmark);
router.post('/batch', protect, authorize('admin'), createBookmarksBatch);
router.post('/import/html', protect, authorize('admin'), importBookmarksFromHtml);

module.exports = router; 